<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>客户退货</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/my.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="">首页</a>
      <a href="">演示</a>
      <a>
        <cite>客户退货</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">
    <div class="layui-row">
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('录入','/productReturn/Return')"><i
                class="layui-icon"></i>录入</button>
        <span class="x-right" style="line-height:40px">一共有<span th:text="${info.total}"></span>条数据</span>
    </xblock>
    <form class="layui-form layui-col-md12 x-so" action="/productReturn/return" id="searchForm" method="get">
        <select id="condition" name="condition" lay-filter="switchItem" style="width: 150px">
            <option value="----">----</option>
            <option value="产品名称">产品名称</option>
            <option value="客户">客户</option>
            <option value="退货日期范围">退货日期范围</option>
        </select>
        <input th:value="${preCondition}" type="text" id="preCondition" style="display: none"
               name="preCondition" autocomplete="off" class="layui-input">
        <input class="layui-input" name="conValue"  id="conValue" type="text" placeholder="请输入查询条件" autocomplete="off" style="width: 250px">
        <input th:value="${start}" class="layui-input" placeholder="起始日期" name="startDate" id="startDate" style="width: 250px">
        <input th:value="${end}" class="layui-input" placeholder="截止日期" name="endDate" id="endDate" style="width: 250px">
        <button class="layui-btn" type="submit" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
    </form>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input class="layui-unselect header layui-form-checkbox" lay-skin="primary" name="getId" th:value="${outId}"><i class="layui-icon">&#xe605;</i>
                </input>
            </th>
            <th style="display: none">退货编号</th>
            <th>产品名称</th>
            <th>退货数量</th>
            <th>退货总金额</th>
            <th>客户</th>
            <th>仓库名称</th>
            <th>操作</th>

        </tr>
        </thead>
        <tbody>
        <tr th:each="i:${info.list}">
            <td>
                <input type="checkbox" name="getId" th:value="${i.outId}">
            </td>
            <td th:text="${i.returnId}" style="display: none"></td>
            <td th:text="${i.productName}"></td>
            <td th:text="${i.returnQuantity}"></td>
            <td th:text="${i.returnAmount}"></td>
            <td th:text="${i.clientName}"></td>
            <td th:text="${i.warehouseName}"></td>

            <td>
                <a href="javascript:;" onclick="getDetail(this)" class="layui-btn layui-btn-normal" >查看详情</a>
                <a href="javascript:;" onclick="delInfo(this)" class="layui-btn layui-btn-normal" >删除</a>
                <a href="javascript:;" onclick="update(this)" class="layui-btn layui-btn-normal" >修改</a>
            </td>
        </tr>
        </tbody>
    </table>
    <div>
        <a class="layui-btn layui-btn-normal" th:href="@{/productReturn/return(page=${info.pre})}" >上一页</a>
        <a class="layui-btn layui-btn-normal" th:href="@{/productReturn/return(page=${info.next})}" >下一页</a>
        一共有<span th:text="${info.totalPage}"></span>页
        当前第<span th:text="${info.cur}"></span>页
    </div>

</div>
<script>
    function search() {
        var preCondition = $("#preCondition").val();
        if(preCondition == "退货日期范围"){
            $("#condition").val("退货日期范围");
            $("#startDate").show();
            $("#endDate").show();
            $("#conValue").hide();
        }else{
            $("#startDate").hide();
            $("#endDate").hide();
            $("#conValue").show();
        }
    }

    //定义文档加载函数
    $(function(){
        //查询使得输入框为单输入框
        search();
    })

    layui.use(['layer', 'jquery', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        //根据不同条件显示不同的input框
        form.on('select(switchItem)', function(data){
            if(data.value == "退货日期范围"){
                $("#startDate").show();
                $("#endDate").show();
                $("#conValue").hide();
            }else{
                $("#startDate").hide();
                $("#endDate").hide();
                $("#conValue").show();
            }
        });

        //根据条件进行搜索
        form.on('submit(search)', function(data){
            document.getElementById("searchForm").submit();
        });
    });

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例-->
        laydate.render({
            elem: '#startDate' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#endDate' //指定元素
        });
    });

    function delInfo(obj) {
        var id=$(obj).parent().parent().find("td").eq(1).text();
        layer.confirm("是否删除该信息？",{icon:3,title:"提示"},function (index) {
            $.ajax({
                url:"/productReturn/delInfo",
                type:"get",
                data:{"returnId":id},
                dataType:"json",//返回的数据类型
                success:function(data) {
                    layer.alert(data.info)
                    if (data.info == "删除成功") {
                        //刷新
                        $(obj).parent().parent().remove();
                    }
                }
            })

        });
    }
    //查看详情
    function getDetail(obj) {
        var id=$(obj).parent().parent().find("td").eq(1).text();
        x_admin_show("详情","/productReturn/getDetail?returnId="+id);

    }
    //修改
    function update(obj) {
        var id=$(obj).parent().parent().find("td").eq(1).text();
        x_admin_show("修改","/productReturn/update?returnId="+id);
    }


    function delAll(arguments) {
        var data = tableCheck.getData();
        var values=[]
        $("input[name='getId']:checked").each(function(){
            var value={"returnId":$(this).val()}
            values.push(value)
        });
        console.log(values);
        layer.confirm('确认要删除吗？'+data, function (index) {
            $.ajax({
                url:"/productReturn/delAll",
                type:"post",
                data:JSON.stringify(values),
                dataType:"json",
                contentType : 'application/json',
                success:function (data) {
                    layer.alert(data.info);
                    if(data.info=="删除成功"){
                        $(arguments).parent().parent().remove();
                    }
                }
            })
            layer.close(index);

        });
    }
</script>
<script>var _hmt = _hmt || []; (function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>